<?php

namespace app\kefu\controller;

use app\BaseController;
use app\Request;
use app\user\service\KefuService;

/**
 * 客服登录
 * Class Login
 * @package app\controller\kefu
 * @author dgc<453342213@qq.com>
 * createTime:2020/8/24 11:53
 */
class Login extends BaseController
{
    /**
     * 客服登录
     * @author dgc<453342213@qq.com>
     * createTime:2020/8/24 11:53
     */
    public function index()
    {
        try {
            $service = new KefuService();
            $data = $this->checkParam(['username', 'password']);
            $token = $service->Login($data);
            returnDate($token);
        } catch (\Exception $e) {
            returnMsg($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 退出登录
     * @param Request $request
     * @author dgc<453342213@qq.com>
     * createTime:2020/8/24 11:52
     */
    public function out(Request $request)
    {
        try {
            $token = $request->header('token');
            redisHdel('login_info', 'kf_'.$token);
            returnDate();
        } catch (\Exception $e) {
            returnMsg($e->getMessage(), $e->getCode());
        }
    }
}
